//获取流程管理配置数据
import buildingApi from '@/config/server/api/building';
import dt from '@dt/dt'
import tool from '@/common/tool.js'

function listByProcess() {
  return buildingApi.product.listByHousesId.fetch({
    housesId: '104873'
  }).then(res => {
    return res.map(item => {
      item.key = item.productId.toString()
      item.value = item.productName
      return item
    })
  })
}

let process = []

function getprocess() {
  //   if (!hid && tool.getStorage('isbuildFlag') == 'buildpage') {
  //     hid = dt.buildInfo().housesId
  //   }
  //   if (hid) {
  return listByProcess().then(res => {
    process = res
    return Promise.resolve(process)
  })
  //   }

}

function create(opt = {}) { // key data multiple hid
  return {
    title: opt.title,
    placeholder: opt.placeholder || '请选择',
    key: opt.key,
    disabled: opt.disabled,
    load: (o) => {
      getprocess().then(res => {
        o.select.options = res
      })
    },
    select: {
      options: process,
      multiple: opt.multiple,
      maxTagCount: opt.maxTagCount,
    },
    data: opt.data,
    rules: [{
      required: true,
      type: opt.type,
      message: '请选择节点',
      trigger: 'blur'
    }]
  }
}

export default {
  create
}